<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户注册</title>
    <style>
        /* 全局样式 */
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: 'Segoe UI', 'PingFang SC', 'Microsoft Yahei', sans-serif;
            background: linear-gradient(135deg, #e0f7fa, #f3e5f5);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 40px 20px;
            color: #333;
        }

        .card {
            background: white;
            width: 100%;
            max-width: 400px;
            padding: 30px 25px;
            border-radius: 16px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
            transition: all 0.3s ease;
        }

        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
        }

        h2 {
            text-align: center;
            margin-bottom: 24px;
            font-weight: 600;
            color: #374151;
        }

        label {
            display: block;
            margin-bottom: 5px;
            color: #4b5563;
        }

        input[type="text"],
        input[type="password"],
        input[type="email"],
        input[type="number"],
        select {
            width: 100%;
            padding: 8px;
            margin-bottom: 1rem;
            border: 1px solid #ccc;
            border-radius: 6px;
        }

        button {
            width: 100%;
            padding: 10px;
            background-color: #d1ecf1;
            color: #15576b;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            font-size: 16px;
        }

        button:hover {
            background-color: #aee2eb;
            color: #0f3d4d;
        }

        .error {
            color: red;
            text-align: center;
            margin-bottom: 1rem;
        }

        .btn-link {
            display: inline-block;
            margin-top: 1rem;
            text-align: center;
            color: #15576b;
            text-decoration: none;
        }

        .btn-link:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>

<div class="card">
    <h2>用户注册</h2>
    <% if (request.getAttribute("error") != null) { %>
    <p class="error"><%= request.getAttribute("error") %></p>
    <% } %>
    <form action="RegisterServlet" method="post" onsubmit="return validateForm()">
        <label for="username">用户名:</label>
        <input type="text" id="username" name="username" required>

        <label for="password">密码:</label>
        <input type="password" id="password" name="password" required>

        <label for="password_again">确认密码:</label>
        <input type="password" id="password_again" name="password_again" required>

        <label for="email">邮箱:</label>
        <input type="email" id="email" name="email" required>

        <label for="age">年龄:</label>
        <input type="number" id="age" name="age" min="0" max="150" required>

        <!-- 新增：用户类型选择 -->
        <label for="userType">用户类型:</label>
        <select id="userType" name="userType" required>
            <option value="">请选择身份</option>
            <option value="student">学生</option>
            <option value="teacher">教师</option>
            <option value="admin">管理员</option>
        </select>

        <button type="submit">注册</button>
    </form>
    <br/>
    <a href="login.jsp" class="btn-link">已有账号？立即登录</a>
</div>

<script>
    function validateForm() {
        const password = document.getElementById('password').value.trim();
        const passwordAgain = document.getElementById('password_again').value.trim();
        const userType = document.getElementById('userType').value;

        if (password !== passwordAgain) {
            alert('两次输入密码不一致');
            return false;
        }
        if (password.length < 6) {
            alert('密码长度不能少于6位');
            return false;
        }
        if (!userType) {
            alert('请选择用户类型');
            return false;
        }
        return true;
    }
</script>

</body>
</html>
